package com.spring.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.spring.controller.dto.MongoTestDTO;
import com.spring.controller.service.impl.TestServiceImpl;

@SuppressWarnings("rawtypes")
@Controller
public class MongoCRUDController extends BaseController {

	@Autowired
	private TestServiceImpl serv;
	
	@RequestMapping
	@ResponseBody
	public ApiModel saveObj(@ModelAttribute MongoTestDTO vo){
		System.out.println("save vo+++++++++++++++++++++++");
		boolean rs = serv.saveTest(vo);
		return buildSuccMsg(rs);
	}
	
	@RequestMapping
	@ResponseBody
	public ApiModel findObj(Long id){
		System.out.println("find vo+++++++++++++++++++++++");
		MongoTestDTO o = serv.findObjById(id);
		return buildSuccMsg(o);
	}
	
	@RequestMapping
	@ResponseBody
	public ApiModel deleteObj(Long id){
		System.out.println("delete vo+++++++++++++++++++++++");
		boolean rs = serv.delObjById(id);
		return buildSuccMsg(rs);
	}
	
	@RequestMapping
	@ResponseBody
	public ApiModel updateObj(MongoTestDTO vo){
		System.out.println("update vo+++++++++++++++++++++++");
		boolean rs = serv.updateObj(vo);
		return buildSuccMsg(rs);
	}
	
	@RequestMapping
	@ResponseBody
	public ApiModel updateObjName(Integer id, String name){
		System.out.println("update name+++++++++++++++++++++++");
		boolean rs = serv.updateObjName(id, name);
		return buildSuccMsg(rs);
	}
	
	@RequestMapping
	@ResponseBody
	public ApiModel test(){
		return buildSuccMsg("do it!");
	}
}
